package com.yaolisheng.poetryandode.controller;

import com.yaolisheng.poetryandode.common.result.Page;
import com.yaolisheng.poetryandode.common.utils.MDToText;
import com.yaolisheng.poetryandode.common.utils.MDUtil;
import com.yaolisheng.poetryandode.entity.TBlog;
import com.yaolisheng.poetryandode.service.TBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;


/**
 * @author yaolisheng
 * @version 1.0
 * @date 2021/6/2 23:21
 */

@Controller
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private TBlogService blogService;

    @RequestMapping(path = "/index", method = RequestMethod.GET)
    public String getIndexPage(Model model, Page page) {


        List<TBlog> tBlogs = blogService.queryAllByLimit(0, 10);
        for (TBlog tb : tBlogs) {
            String str = MDToText.mdToText(tb.getContent());
            tb.setContent(str);
        }

        model.addAttribute("lists",tBlogs);
        return "index";
    }

}
